package com.wallet;

public class ServiceForUser {
    private wallet w;
    private walletForStore wfs;
    private dataBase db;
    private StringBuffer checker;//流水记录
    ServiceForUser(double n0,double n1){
        db = new dataBase(n0,n1);
        w = new wallet();
        wfs = new walletForStore();
        checker = new StringBuffer();
    }

//    public void initializer(){
//        ServiceForUser service = new ServiceForUser();
//    }
    public void showRemain(){
        System.out.println(w.getRemain());
    }
    public void showChecker(){
        //查看流水
        System.out.println(checker);
    }

    public void deposit(double n){
        if(db.b.getMoney() < n){
            System.out.println("银行卡余额不足");
            return;
        }
        w.getDeposit(n);
        db.b.depositFromBank(n);
        checker.append("成功充值"+n+"元\n");
        w.showRemain();
        db.b.showMoney();
//        showChecker();


    }
    public void cashOut(double n){
        if(w.getRemain() < n){
            System.out.println("余额不足");
            return;
        }
        w.CashOut(n);
        db.b.CashToBank(n);
        checker.append("成功提现"+n+"元\n");
        w.showRemain();
        db.b.showMoney();
//        showChecker();
    }

    //所谓支付，就是将钱包中的虚拟货币直接向商家银行卡提现。
    public void pay(double n){
        if(w.getRemain() < n){
            System.out.println("余额不足！");
            return;
        }
        w.CashOut(n);
        wfs.getFromUser(n);
        checker.append("成功购买价值"+n+"元的商品\n");

    }


}
